/*******************************************************************************
 * Package: com.hadoop
 * Type:    HadoopApp
 * Date:    2024-05-12 10:41
 *
 * Copyright (c) 2024 LTD All Rights Reserved.
 *
 * You may not use this file except in compliance with the License.
 *******************************************************************************/
package com.hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;


/**
 * 功能描述：
 *
 * @author Songxianyang
 * @date 2024-05-12 10:41
 */
@SpringBootTest
public class HadoopApp {
    private String userName = "SongXianYang";
    private  URI uri = null;
    private  Configuration configuration = new Configuration();
    private FileSystem fs;

    @BeforeEach
    private void before() throws URISyntaxException, IOException, InterruptedException {
        uri = new URI("hdfs://localhost:9000");
        fs = FileSystem.get(uri, configuration, userName);
        System.out.println("----之前");
    }
    @Test
    private void mkdir() throws IOException {
        Path path = new Path("/hadooptest");
        boolean mkdirs = fs.mkdirs(path);
        System.out.println(mkdirs);
    }

    @AfterEach
    private void after() {
        uri = null;
        fs = null;
        System.out.println("之后");
    }



    public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
        Configuration configuration = new Configuration();
        URI uri = new URI("hdfs://localhost:9000");
        FileSystem fs = FileSystem.get(uri, configuration, "SongXianYang");
        Path path = new Path("/hadooptest");
        boolean mkdirs = fs.mkdirs(path);
        System.out.println(mkdirs);
    }
}
